import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('../views/Home/index.vue'),
      children: [
        {
          path: '',
          name: 'blogs',
          component: () => import('../views//Home/Content/index.vue'),
        },
        {
          path: 'addblog',
          name: 'addblog',
          component: () => import('../views/Home/Content/addBlog.vue'),
        },
      ],
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/index.vue'),
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('../views/Login/register.vue'),
    },
    {
      path: '/user',
      name: 'user',
      component: () => import('../views/User/index.vue'),
    },
  ],
})

// 路由白名单，不需要token
const whiteList = ['login', 'register']

router.beforeEach((to, from, next) => {
  console.log(to)

  // if (!localStorage.getItem('token')) {
  //   if (!whiteList.includes(to.name)) {
  //     next({ name: 'login' })
  //   }
  // }
  next()
})
export default router
